package org.example.project.entity

import kotlinx.datetime.Instant
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDateTime
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class RocketLaunch(
    @SerialName("flight_number")
    val flightNumber: Int,
    @SerialName("name")
    val missionName: String,
    @SerialName("date_utc")
    val launchDateUTC: String,
    @SerialName("details")
    val details: String?,
    @SerialName("success")
    val launchSuccess: Boolean?,
    @SerialName("links")
    val links: Links
) {
    // 当RocketLaunch对象被创建时，会自动计算launchYear属性的值
    // 每次实例化时都初始化一次
    var launchYear = Instant.parse(launchDateUTC).toLocalDateTime(TimeZone.UTC).year
}

@Serializable
data class Links(
    @SerialName("patch")
    val patch: Patch?,
    @SerialName("reddit")
    val reddit: Reddit?,
    @SerialName("article")
    val article: String?,
    @SerialName("webcast")
    val webcast: String?,
    @SerialName("wikipedia")
    val wikipedia: String?
)

@Serializable
data class Patch(
    @SerialName("small")
    val small: String?,
    @SerialName("large")
    val large: String?
)

@Serializable
data class Reddit(
    @SerialName("campaign")
    val campaign: String?,
    @SerialName("launch")
    val launch: String?,
    @SerialName("media")
    val media: String?,
    @SerialName("recovery")
    val recovery: String?
)